#—*—coding:utf-8 -*-
#@Time        :2022/7/16 16:43
#@Author      :dhx
#@File        :richeng_page.py
# @Software: PyCharm
from time import sleep

from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

from pages.base_pageage import BasePage

class RiCheng(BasePage):
    url='http://192.168.3.133/crm/index.php?m=event&a=add'
    # 定位器
    richen_locator = (By.CSS_SELECTOR, '#calendar > div.c-event-grid > div.c-event-body > div.data-head > a > i')
    topic_locator = (By.ID, 'subject')  # 名称
    person_locator = (By.ID, 'owner_name')  # 负责人
    gouxuan_locator = (
    By.CSS_SELECTOR, '#d_content > tr:nth-child(1) > td:nth-child(1) > input[type=radio]')  # 勾选第一条
    qued_locator = (By.XPATH, '/html/body/div[7]/div[3]/div/button[1]')
    riqi_locator = (By.ID, 'start_date')  # 开始时间
    jiesu_locator = (By.ID, 'end_date')  # 结束时间
    didian_locator = (By.ID, 'venue')  # 地点
    shi_locator = (By.XPATH, '/html/body/div[5]/div[2]/div/form/table/tbody/tr[4]/td[4]/input[1]')
    xiangguan_locator = (By.ID, 'select1')
    miaosu_locator = (By.XPATH, '/html/body/div[5]/div[2]/div/form/table/tbody/tr[6]/td[2]/textarea')
    baocun_locator = (By.XPATH, '/html/body/div[5]/div[2]/div/form/table/tfoot/tr/td[2]/input[1]')
    def add_richeng(self):
        """添加任务"""
        self.driver.find_element(*self.richen_locator).click()
    def input_topic(self):
        """输入主题"""
        self.driver.find_element(*self.topic_locator).send_keys("主题")
    def option_person(self):
        """选择负责人"""
        self.driver.find_element(*self.person_locator).click()
        sleep(1)
    def first_person(self):
        """选择第一个负责人"""
        self.driver.find_element(*self.gouxuan_locator).click()
        sleep(1)
    def confir(self):
        """点击确定"""
        self.driver.find_element(*self.qued_locator).click()
        sleep(1)
    def date_richen(self):
        """日期"""
        self.driver.find_element(*self.riqi_locator).send_keys("2022-06-18")
        sleep(1)
    def end_time(self):
        """日期"""
        self.driver.find_element(*self.jiesu_locator).send_keys("2022-07-14")
        sleep(1)
    def place(self):
        """地点"""
        self.driver.find_element(*self.didian_locator).send_keys("四川省成都市")
        sleep(1)
    def email_richeng(self):
        """选择站内信"""
        self.driver.find_element(*self.shi_locator).click()
        sleep(1)
    def option_relate(self):
        """选择相关"""
        relate = self.driver.find_element(*self.xiangguan_locator)
        select = Select(relate)
        select.select_by_index(1)
        sleep(1)
    def desc_richeng(self):
        """输入描述"""
        self.driver.find_element(*self.miaosu_locator).send_keys("描述")
        sleep(1)
    def save_richeng(self):
        """输入描述"""
        self.driver.find_element(*self.baocun_locator).click()
        sleep(1)


